<template>
    <div><van-nav-bar
  fixed
  placeholder>
  <template #left>
<img src="../../assets/toutiao_logo.png" alt="">
</template>
 <template #right>
    <van-icon name="search" size="0.48rem" />
  </template>
</van-nav-bar>
<!-- 标签栏 -->
<van-tabs v-model="active"
   animated
   sticky
   offset-top = '1.22666667rem'
   >
  <van-tab v-for="obj in userChannelList"
   :key="obj.id"
   :name="obj.id"
  :title="obj.name">
  <artucke-list :channelId="active"></artucke-list>
  </van-tab>
</van-tabs>
  <van-action-sheet v-model="$store.state.homeArticleActionShow"
  :actions="actionArr"
  :cancel-text="cancelText"
   @select="onSelect"
   @cancel='cancelFn'
   get-container="body" />
</div>
</template>
<script>
import { getUserChannelListAPI, dislikeArticleAPI } from '@/api'
import ArtuckeList from './ArtuckeList'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      active: 0,
      userChannelList: [],
      show: false,
      actionArr: [],
      cancelText: '取消'
    }
  },
  computed: {
    ...mapState(['firstActions', 'secondActions', 'actionArtId'])
  },
  methods: {
    ...mapMutations(['changeActionShowMutations']),
    async onSelect (item) {
      if (item.name === '反馈垃圾内容') {
        this.actionArr = this.secondActions
        this.cancelText = '返回'
      } else if (item.name === '不感兴趣') {
        console.log(this.actionArtId)
        const res = await dislikeArticleAPI(this.actionArtId)
        console.log(res)
        this.changeActionShowMutations(false)
      }
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
    },
    cancelFn () {
      if (this.cancelText === '返回') {
        this.changeActionShowMutations(true)
        this.actionArr = this.firstActions
        this.cancelText = '取消'
      }
    }
  },

  components: {
    ArtuckeList
  },
  async created () {
    // console.log(111)
    const res = await getUserChannelListAPI()
    // console.log(res)
    this.userChannelList = res.data.data.channels
    // console.log(this.userChannelList)
    this.actionArr = this.firstActions
  }
}
</script>
<style scoped lang='less'>
/deep/ .van-nav-bar__left img{
    width: 100px;
    height: 30px;
}
</style>
